package org.hzz.application.command.user;

import io.gitee.pkmer.convention.page.PageResponse;
import io.gitee.pkmer.convention.page.query.FilterCondition;
import io.gitee.pkmer.convention.page.query.PageQuery;
import io.gitee.pkmer.ddd.shared.command.CommandWithMark;
import io.gitee.pkmer.ddd.shared.service.CmdService;
import lombok.Value;
import org.hzz.application.handler.user.ShowCouponCmdHandler;
import org.hzz.promotions.types.constants.CouponFields;
import org.hzz.promotions.types.enums.coupon.CouponStatus;
import org.hzz.promotions.types.enums.coupon.ObtainWay;
import org.hzz.promotions.types.vo.ShowCouponVo;

import java.util.List;

import static io.gitee.pkmer.convention.page.query.FilterCondition.Operation.EQ;

/**
 * @author <a href="mailto:1193094618@qq.com">pkmer</a>
 * <br>
 * <a href = "https://gitee.com/developeros/videos-online">Code Repository</a>
 * At 2024/9/2
 * 分页查询展示给用户可用的优惠券
 * {@link ShowCouponCmdHandler}
 */
@Value(staticConstructor = "commandOf")
public class ShowCouponCmd implements CommandWithMark {
    public static final String MARK = ShowCouponCmd.class.getName();

    Long userId;

    PageQuery pageQuery;
    @Override
    public String mark() {
        return MARK;
    }

    public PageResponse<ShowCouponVo> executeWithResult(CmdService cmdService) {
        addFilters();
        return cmdService.handleCommandWithResult(this);
    }

    private void addFilters(){
        List<FilterCondition> filters = FilterCondition.createCriteria()
                .and(CouponFields.STATUS, EQ, CouponStatus.ISSUING)
                .and(CouponFields.OBTAIN_WAY, EQ, ObtainWay.GET_BY_HAND)
                .build();

        pageQuery.setFilters(filters);
    }
}
